package main

func main() {
	println(longestConsecutive("abcabcbb"))
}

func longestConsecutive(str string) int {
	mapCount := map[byte]int{}
	j := 0
	maxLength := 0
	for i := 0; i < len(str); i++ {
		mapCount[str[i]]++
		for mapCount[str[i]] > 1 && j < i {
			mapCount[str[j]]--
			j++
		}
		maxLength = max(maxLength, i-j+1)
	}
	return maxLength
}
